package org.sean.framework.canary.event;

import lombok.Getter;
import org.sean.framework.canary.core.CanaryUtils;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.context.ApplicationEvent;

import java.util.Map;

/**
 * 服务选中事件
 *
 * @author xielei
 */
@Getter
public class CanaryServerEvent extends ApplicationEvent {
    private final String name;
    private final String schema;
    private final Map<String, String> metadata;
    private final String host;
    private final int port;
    private final String label;

    public CanaryServerEvent(String name, ServiceInstance server) {
        super(server);
        this.name = name;
        this.host = server.getHost();
        this.port = server.getPort();
        this.schema = server.getScheme();
        this.metadata = server.getMetadata();
        this.label = CanaryUtils.getServerLabel(server);
    }

}
